# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=cargo-update
pkgver=13.4.0
pkgrel=0
pkgdesc="cargo subcommand for checking and applying updates to installed executables"
url="https://github.com/nabijaczleweli/cargo-update"
arch="all"
license="MIT"
makedepends="cargo cargo-auditable ronn curl-dev libgit2-dev libssh-dev"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/nabijaczleweli/cargo-update/archive/refs/tags/v$pkgver.tar.gz"

export LIBSSH2_SYS_USE_PKG_CONFIG=1

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET"
}

build() {
	cargo auditable build --frozen --release
	ronn --roff --organization="CARGO-UPDATE $pkgver" man/*.md
}

check() {
	TMPDIR="$srcdir" cargo test --frozen
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin/ \
		target/release/cargo-install-update \
		target/release/cargo-install-update-config

	install -Dm644 man/cargo-install-update*.1 \
		-t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
14bf57b1624ada761f914acab3aae2211f7a97f9e40ebf8697fe3b82ba856836d8daff627a658540ad7b9d0aae7173e2803b2bbe001213d785dee22c24634d37  cargo-update-13.4.0.tar.gz
"
